package com.h3c.web.rest;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.h3c.web.common.utils.SpringContextUtil;
import com.h3c.web.support.cas.common.ClientInfo;
import com.h3c.web.support.cas.common.ClientInfoHolder;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

@Controller
@RequestMapping("console/tool")
/**
 * @ClassName: ToolRest
 * @Description: 工具api for开发
 * @author: d14287
 * @date: 2017年5月31日 下午3:49:57
 */
public class ToolRest {
	@RequestMapping(value = "/beans.ajax", method = RequestMethod.GET)
	public @ResponseBody List<String> queryBeans(HttpServletRequest request) {
		String[] beanNames = SpringContextUtil.getBeanNames();
		return Arrays.asList(beanNames);
	}
	@RequestMapping(value = "/groovy.ajax", method = RequestMethod.POST)
	public @ResponseBody Object groovyShell(@RequestParam(value = "script", required = false) String script,
			HttpServletRequest request) {
		Binding binding = new Binding();
		binding.setVariable("var", 5);
		GroovyShell gs = new GroovyShell(binding);
		Object result = gs.evaluate(script);
		return result;
	}
	@RequestMapping(value = "/clientInfo.ajax", method = RequestMethod.GET)
	public @ResponseBody Map<String, ClientInfo> clientInfo() {
		return ClientInfoHolder.get();
	}
}
